import { computed, onMounted, ref } from 'vue';
import { timelineByDate } from '../services/api';
const date = ref(new Date().toISOString().slice(0, 10));
const filter = ref('ALL');
const loading = ref(false);
const rawItems = ref([]);
const displayItems = computed(() => {
    const arr = (filter.value === 'ALL'
        ? rawItems.value
        : rawItems.value.filter((i) => i.type === filter.value))
        .map((i, idx) => {
        return {
            key: `${i.type}-${idx}-${i.eventTime}`,
            time: formatTime(i.eventTime),
            typeText: mapTypeText(i.type),
            content: summarize(i)
        };
    });
    return arr;
});
function mapTypeText(t) {
    switch (t) {
        case 'FEEDING': return '喂奶';
        case 'DIAPER': return '尿布';
        case 'SLEEP': return '睡眠';
        case 'CRY': return '哭闹';
    }
}
function summarize(i) {
    if (i.type === 'FEEDING') {
        const d = i.data;
        return d.feedingType === 'FORMULA'
            ? `配方奶 ${d.formulaMl ?? '-'} ml`
            : `母乳 左${d.leftMinutes ?? 0}分 右${d.rightMinutes ?? 0}分`;
    }
    if (i.type === 'DIAPER')
        return `${mapDiaper(dSafe(i).diaperType)}`;
    if (i.type === 'SLEEP') {
        const d = i.data;
        const start = formatTime(d.sleepStart);
        const end = d.sleepEnd ? formatTime(d.sleepEnd) : '至今';
        return `睡眠 ${start} - ${end}`;
    }
    if (i.type === 'CRY') {
        const d = i.data;
        return `哭闹 ${formatTime(d.startTime)}${d.endTime ? ' - ' + formatTime(d.endTime) : ''}`;
    }
    return '';
}
function dSafe(i) { return i.data || {}; }
function mapDiaper(t) { return t === 'WET' ? '清尿' : t === 'DIRTY' ? '便便' : '混合'; }
function formatTime(iso) { const d = new Date(iso); return d.toTimeString().slice(0, 5); }
async function load() {
    try {
        loading.value = true;
        const payload = { babyId: 1, date: date.value };
        const res = await timelineByDate(payload);
        rawItems.value = Array.isArray(res) ? res : [];
    }
    finally {
        loading.value = false;
    }
}
onMounted(load);
debugger; /* PartiallyEnd: #3632/scriptSetup.vue */
const __VLS_ctx = {};
let __VLS_components;
let __VLS_directives;
// CSS variable injection 
// CSS variable injection end 
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
    ...{ class: "space-y-4" },
});
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
    ...{ class: "card flex items-center gap-3" },
});
__VLS_asFunctionalElement(__VLS_intrinsicElements.input)({
    ...{ onChange: (__VLS_ctx.load) },
    type: "date",
    ...{ class: "input w-auto" },
});
(__VLS_ctx.date);
__VLS_asFunctionalElement(__VLS_intrinsicElements.select, __VLS_intrinsicElements.select)({
    ...{ onChange: (__VLS_ctx.load) },
    ...{ class: "input w-auto" },
    value: (__VLS_ctx.filter),
});
__VLS_asFunctionalElement(__VLS_intrinsicElements.option, __VLS_intrinsicElements.option)({
    value: "ALL",
});
__VLS_asFunctionalElement(__VLS_intrinsicElements.option, __VLS_intrinsicElements.option)({
    value: "FEEDING",
});
__VLS_asFunctionalElement(__VLS_intrinsicElements.option, __VLS_intrinsicElements.option)({
    value: "DIAPER",
});
__VLS_asFunctionalElement(__VLS_intrinsicElements.option, __VLS_intrinsicElements.option)({
    value: "SLEEP",
});
__VLS_asFunctionalElement(__VLS_intrinsicElements.option, __VLS_intrinsicElements.option)({
    value: "CRY",
});
__VLS_asFunctionalElement(__VLS_intrinsicElements.button, __VLS_intrinsicElements.button)({
    ...{ onClick: (__VLS_ctx.load) },
    ...{ class: "btn-primary" },
});
if (__VLS_ctx.loading) {
    __VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
        ...{ class: "text-center text-gray-500" },
    });
}
else {
    __VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
        ...{ class: "space-y-3" },
    });
    if (__VLS_ctx.displayItems.length === 0) {
        __VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
            ...{ class: "text-center text-gray-500" },
        });
    }
    for (const [item] of __VLS_getVForSourceType((__VLS_ctx.displayItems))) {
        __VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
            key: (item.key),
            ...{ class: "card" },
        });
        __VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
            ...{ class: "text-sm text-gray-500" },
        });
        (item.time);
        (item.typeText);
        __VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
            ...{ class: "mt-1" },
        });
        (item.content);
    }
}
/** @type {__VLS_StyleScopedClasses['space-y-4']} */ ;
/** @type {__VLS_StyleScopedClasses['card']} */ ;
/** @type {__VLS_StyleScopedClasses['flex']} */ ;
/** @type {__VLS_StyleScopedClasses['items-center']} */ ;
/** @type {__VLS_StyleScopedClasses['gap-3']} */ ;
/** @type {__VLS_StyleScopedClasses['input']} */ ;
/** @type {__VLS_StyleScopedClasses['w-auto']} */ ;
/** @type {__VLS_StyleScopedClasses['input']} */ ;
/** @type {__VLS_StyleScopedClasses['w-auto']} */ ;
/** @type {__VLS_StyleScopedClasses['btn-primary']} */ ;
/** @type {__VLS_StyleScopedClasses['text-center']} */ ;
/** @type {__VLS_StyleScopedClasses['text-gray-500']} */ ;
/** @type {__VLS_StyleScopedClasses['space-y-3']} */ ;
/** @type {__VLS_StyleScopedClasses['text-center']} */ ;
/** @type {__VLS_StyleScopedClasses['text-gray-500']} */ ;
/** @type {__VLS_StyleScopedClasses['card']} */ ;
/** @type {__VLS_StyleScopedClasses['text-sm']} */ ;
/** @type {__VLS_StyleScopedClasses['text-gray-500']} */ ;
/** @type {__VLS_StyleScopedClasses['mt-1']} */ ;
var __VLS_dollars;
const __VLS_self = (await import('vue')).defineComponent({
    setup() {
        return {
            date: date,
            filter: filter,
            loading: loading,
            displayItems: displayItems,
            load: load,
        };
    },
});
export default (await import('vue')).defineComponent({
    setup() {
        return {};
    },
});
; /* PartiallyEnd: #4569/main.vue */
